{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

{{#if @isInDropdown}}
  {{! Hds component renders <li> and <button> elements }}
  <Hds::Dropdown::ListItem::Interactive
    data-test-confirm-action-trigger
    @text={{@buttonText}}
    @color="critical"
    {{on "click" (fn (mut this.showConfirmModal) true)}}
    ...attributes
    {{! remove class when dropdown/popup menus are replaced with Hds::Dropdown }}
    class="hds-confirm-action-critical"
  />
{{else}}
  <Hds::Button
    data-test-confirm-action-trigger
    @text={{@buttonText}}
    @color={{@buttonColor}}
    {{on "click" (fn (mut this.showConfirmModal) true)}}
    ...attributes
  />
{{/if}}

{{#if this.showConfirmModal}}
  <Hds::Modal
    id="confirm-action-modal"
    class="has-text-left"
    @color={{this.modalColor}}
    @size="small"
    @onClose={{fn (mut this.showConfirmModal) false}}
    as |M|
  >
    {{#if @disabledMessage}}
      <M.Header data-test-confirm-action-title @icon="x-circle">
        Not allowed
      </M.Header>
      <M.Body data-test-confirm-action-message>
        {{@disabledMessage}}
      </M.Body>
      <M.Footer as |F|>
        <Hds::Button data-test-confirm-cancel-button @text="Close" {{on "click" F.close}} />
      </M.Footer>
    {{else}}
      <M.Header data-test-confirm-action-title @icon="alert-circle">
        {{or @confirmTitle "Are you sure?"}}
      </M.Header>
      <M.Body data-test-confirm-action-message>
        {{this.confirmMessage}}
      </M.Body>
      <M.Footer as |F|>
        <Hds::ButtonSet>
          <Hds::Button
            data-test-confirm-button
            disabled={{@isRunning}}
            @icon={{if @isRunning "loading"}}
            @color={{if (eq this.modalColor "critical") "critical" "primary"}}
            @text="Confirm"
            {{on "click" this.onConfirm}}
          />
          <Hds::Button data-test-confirm-cancel-button @color="secondary" @text="Cancel" {{on "click" F.close}} />
        </Hds::ButtonSet>
      </M.Footer>
    {{/if}}
  </Hds::Modal>
{{/if}}